home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevpdfw.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  17.2 KB  |  581 lines

  1. /* Copyright (C) 1999, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevpdfw.c,v 1.5 2000/09/19 19:00:17 lpd Exp $ */
  20. /* Font writing for pdfwrite driver. */
  21. #include "memory_.h"
  22. #include "string_.h"
  23. #include "gx.h"
  24. #include "gsbittab.h"
  25. #include "gserrors.h"
  26. #include "gsmalloc.h"        /* for patching font memory */
  27. #include "gsmatrix.h"
  28. #include "gsutil.h"        /* for bytes_compare */
  29. #include "gxfcid.h"
  30. #include "gxfont.h"
  31. #include "gxfont0.h"
  32. #include "gdevpdfx.h"
  33. #include "gdevpdff.h"
  34. #include "gdevpsf.h"
  35. #include "scommon.h"
  36.  
  37. /* Get the ID of various kinds of resources, with type checking. */
  38. inline private long
  39. pdf_font_id(const pdf_font_t *pdfont)
  40. {
  41.     return pdf_resource_id((const pdf_resource_t *)pdfont);
  42. }
  43. inline private long
  44. pdf_font_descriptor_id(const pdf_font_descriptor_t *pfd)
  45. {
  46.     return pdf_resource_id((const pdf_resource_t *)pfd);
  47. }
  48. inline private long
  49. pdf_char_proc_id(const pdf_char_proc_t *pcp)
  50. {
  51.     return pdf_resource_id((const pdf_resource_t *)pcp);
  52. }
  53.  
  54. /* Write CIDSystemInfo for a CIDFont or CMap. */
  55. private void
  56. pdf_write_CIDSystemInfo(gx_device_pdf *pdev,
  57.             const gs_cid_system_info_t *pcidsi)
  58. {
  59.     stream *s = pdev->strm;
  60.  
  61.     pputs(s, "/CISystemInfo<<\n/Registry");
  62.     s_write_ps_string(s, pcidsi->Registry.data, pcidsi->Registry.size,
  63.               PRINT_HEX_NOT_OK);
  64.     pputs(s, "\n/Ordering");
  65.     s_write_ps_string(s, pcidsi->Ordering.data, pcidsi->Ordering.size,
  66.               PRINT_HEX_NOT_OK);
  67.     pprintd1(s, "\n/Supplement %d\n>>\n", pcidsi->Supplement);
  68. }
  69.  
  70. /* Write the Widths for a font. */
  71. private int
  72. pdf_write_Widths(gx_device_pdf *pdev, int first, int last,
  73.          const int widths[256])
  74. {
  75.     stream *s = pdev->strm;
  76.     int i;
  77.  
  78.     pprintd2(s, "/FirstChar %d/LastChar %d/Widths[", first, last);
  79.     for (i = first; i <= last; ++i)
  80.     pprintd1(s, (i & 15 ? " %d" : "\n%d"), widths[i]);
  81.     pputs(s, "]\n");
  82.     return 0;
  83. }
  84.  
  85. /* Write a FontBBox dictionary element. */
  86. private int
  87. pdf_write_font_bbox(gx_device_pdf *pdev, const gs_int_rect *pbox)
  88. {
  89.     stream *s = pdev->strm;
  90.  
  91.     pprintd4(s, "/FontBBox[%d %d %d %d]",
  92.          pbox->p.x, pbox->p.y, pbox->q.x, pbox->q.y);
  93.     return 0;
  94. }
  95.  
  96. /* Write a synthesized bitmap font resource. */
  97. private int
  98. pdf_write_synthesized_type3(gx_device_pdf *pdev, const pdf_font_t *pef)
  99. {
  100.     stream *s;
  101.     gs_int_rect bbox;
  102.     int widths[256];
  103.  
  104.     memset(&bbox, 0, sizeof(bbox));
  105.     memset(widths, 0, sizeof(widths));
  106.     pdf_open_separate(pdev, pdf_font_id(pef));
  107.     s = pdev->strm;
  108.     pprints1(s, "<</Type/Font/Name/%s/Subtype/Type3", pef->frname);
  109.     pprintld1(s, "/Encoding %ld 0 R/CharProcs", pdev->embedded_encoding_id);
  110.  
  111.     /* Write the CharProcs. */
  112.     {
  113.     const pdf_char_proc_t *pcp;
  114.     int w;
  115.  
  116.     pputs(s, "<<");
  117.     /* Write real characters. */
  118.     for (pcp = pef->char_procs; pcp; pcp = pcp->char_next) {
  119.         bbox.p.y = min(bbox.p.y, pcp->y_offset);
  120.         bbox.q.x = max(bbox.q.x, pcp->width);
  121.         bbox.q.y = max(bbox.q.y, pcp->height + pcp->y_offset);
  122.         widths[pcp->char_code] = pcp->x_width;
  123.         pprintld2(s, "/a%ld\n%ld 0 R", (long)pcp->char_code,
  124.               pdf_char_proc_id(pcp));
  125.     }
  126.     /* Write space characters. */
  127.     for (w = 0; w < countof(pef->spaces); ++w) {
  128.         byte ch = pef->spaces[w];
  129.  
  130.         if (ch) {
  131.         pprintld2(s, "/a%ld\n%ld 0 R", (long)ch,
  132.               pdev->space_char_ids[w]);
  133.         widths[ch] = w + X_SPACE_MIN;
  134.         }
  135.     }
  136.     pputs(s, ">>");
  137.     }
  138.  
  139.     pdf_write_font_bbox(pdev, &bbox);
  140.     pputs(s, "/FontMatrix[1 0 0 1 0 0]");
  141.     pdf_write_Widths(pdev, 0, pef->num_chars - 1, widths);
  142.     pputs(s, ">>\n");
  143.     pdf_end_separate(pdev);
  144.     return 0;
  145. }
  146.  
  147. /* Write a font descriptor. */
  148. int
  149. pdf_write_FontDescriptor(gx_device_pdf *pdev, const pdf_font_descriptor_t *pfd)
  150. {
  151.     gs_font *font = pfd->base_font;
  152.     bool is_subset =
  153.     pdf_has_subset_prefix(pfd->FontName.chars, pfd->FontName.size);
  154.     long cidset_id = 0;        /* pro forma initialization */
  155.     stream *s;
  156.     int code = 0;
  157.  
  158.     /* If this is a CIDFont subset, write the CIDSet now. */
  159.     if (font && is_subset) {
  160.     switch (pfd->values.FontType) {
  161.     case ft_CID_encrypted:
  162.     case ft_CID_TrueType: {
  163.         int i;
  164.  
  165.         cidset_id = pdf_begin_separate(pdev);
  166.         s = pdev->strm;
  167.         /****** ADD COMPRESSION + ASCII85 ******/
  168.         pprintd1(s, "<</Length %d>>stream\n", (int)pfd->chars_used.size);
  169.         for (i = 0; i < pfd->chars_used.size; ++i)
  170.         pputc(s, byte_reverse_bits[pfd->chars_used.data[i]]);
  171.         pputs(s, "endstream\n");
  172.         pdf_end_separate(pdev);
  173.     }
  174.     default:
  175.         break;
  176.     }
  177.     }
  178.     pdf_open_separate(pdev, pdf_font_descriptor_id(pfd));
  179.     s = pdev->strm;
  180.     pputs(s, "<</Type/FontDescriptor/FontName");
  181.     pdf_put_name(pdev, pfd->FontName.chars, pfd->FontName.size);
  182.     if (font) {        /* not a built-in font */
  183.     param_printer_params_t params;
  184.     printer_param_list_t rlist;
  185.     gs_param_list *const plist = (gs_param_list *)&rlist;
  186.  
  187.     pdf_write_font_bbox(pdev, &pfd->values.FontBBox);
  188.     params = param_printer_params_default;
  189.     code = s_init_param_printer(&rlist, ¶ms, s);
  190.     if (code >= 0) {
  191. #define DESC_INT(str, memb)\
  192.  {str, gs_param_type_int, offset_of(pdf_font_descriptor_t, values.memb)}
  193.         static const gs_param_item_t required_items[] = {
  194.         DESC_INT("Ascent", Ascent),
  195.         DESC_INT("CapHeight", CapHeight),
  196.         DESC_INT("Descent", Descent),
  197.         DESC_INT("ItalicAngle", ItalicAngle),
  198.         DESC_INT("StemV", StemV),
  199.         gs_param_item_end
  200.         };
  201.         static const gs_param_item_t optional_items[] = {
  202.         DESC_INT("AvgWidth", AvgWidth),
  203.         DESC_INT("Leading", Leading),
  204.         DESC_INT("MaxWidth", MaxWidth),
  205.         DESC_INT("MissingWidth", MissingWidth),
  206.         DESC_INT("StemH", StemH),
  207.         DESC_INT("XHeight", XHeight),
  208.         gs_param_item_end
  209.         };
  210. #undef DESC_INT
  211.         int Flags = pfd->values.Flags;
  212.         pdf_font_descriptor_t defaults;
  213.  
  214.         /*
  215.          * Hack: make all embedded subset TrueType fonts "symbolic" to
  216.          * work around undocumented assumptions in Acrobat Reader.
  217.          */
  218.         if (pfd->values.FontType == ft_TrueType &&
  219.         pdf_has_subset_prefix(pfd->FontName.chars, pfd->FontName.size))
  220.         Flags = (Flags & ~(FONT_IS_ADOBE_ROMAN)) | FONT_IS_SYMBOLIC;
  221.         param_write_int(plist, "Flags", &Flags);
  222.         gs_param_write_items(plist, pfd, NULL, required_items);
  223.         memset(&defaults, 0, sizeof(defaults));
  224.         gs_param_write_items(plist, pfd, &defaults, optional_items);
  225.         s_release_param_printer(&rlist);
  226.     }
  227.     if (is_subset) {
  228.         switch (pfd->values.FontType) {
  229.         case ft_CID_encrypted:
  230.         case ft_CID_TrueType:
  231.         pprintld1(s, "/CIDSet %ld 0 R\n", cidset_id);
  232.         break;
  233.         case ft_composite:
  234.         return_error(gs_error_rangecheck);
  235.         default: {
  236.         gs_glyph subset_glyphs[256];
  237.         uint subset_size = psf_subset_glyphs(subset_glyphs, font,
  238.                              pfd->chars_used.data);
  239.         int i;
  240.  
  241.         pputs(s, "/CharSet(");
  242.         for (i = 0; i < subset_size; ++i) {
  243.             uint len;
  244.             const char *str = font->procs.callbacks.glyph_name
  245.             (subset_glyphs[i], &len);
  246.  
  247.             /* Don't include .notdef. */
  248.             if (bytes_compare((const byte *)str, len,
  249.                       (const byte *)".notdef", 7))
  250.             pdf_put_name(pdev, (const byte *)str, len);
  251.         }
  252.         pputs(s, ")\n");
  253.         }
  254.         }
  255.     }
  256.     if (pfd->FontFile_id) {
  257.         const char *FontFile_key;
  258.  
  259.         switch (pfd->values.FontType) {
  260.         case ft_TrueType:
  261.         case ft_CID_TrueType:
  262.         FontFile_key = "/FontFile2";
  263.         break;
  264.         default:
  265.         code = gs_note_error(gs_error_rangecheck);
  266.         /* falls through */
  267.         case ft_encrypted:
  268.         if (pdev->CompatibilityLevel < 1.2) {
  269.             FontFile_key = "/FontFile";
  270.             break;
  271.         }
  272.         /* For PDF 1.2 and later, write Type 1 fonts as Type1C. */
  273.         case ft_encrypted2:
  274.         case ft_CID_encrypted:
  275.         FontFile_key = "/FontFile3";
  276.         break;
  277.         }
  278.         pputs(s, FontFile_key);
  279.         pprintld1(s, " %ld 0 R", pfd->FontFile_id);
  280.     }
  281.     }
  282.     pputs(s, ">>\n");
  283.     pdf_end_separate(pdev);
  284.     return code;
  285. }
  286.  
  287. /*
  288.  * Write a font resource, including Widths and/or Encoding if relevant,
  289.  * but not the FontDescriptor or embedded font data.  Note that the
  290.  * font itself may not be available.
  291.  */
  292. private int
  293. pdf_write_font_resource(gx_device_pdf *pdev, const pdf_font_t *pef,
  294.             const gs_const_string *pfname,
  295.             const gs_const_string *pbfname)
  296. {
  297.     stream *s;
  298.     const pdf_font_descriptor_t *pfd = pef->FontDescriptor;
  299.     static const char *const encoding_names[] = {
  300.     KNOWN_REAL_ENCODING_NAMES
  301.     };
  302.  
  303.     pdf_open_separate(pdev, pdf_font_id(pef));
  304.     s = pdev->strm;
  305.     switch (pef->FontType) {
  306.     case ft_composite:
  307.     pputs(s, "<</Subtype/Type0");
  308.     goto bfname;
  309.     case ft_encrypted:
  310.     case ft_encrypted2: {
  311.     if (pef->is_MM_instance) {
  312.     /*
  313.      * If the font is a Multiple Master instance, it should be
  314.      * identified as such.  However, Acrobat Reader doesn't seem to
  315.      * recognize the MMType1 subtype, but will accept MM Type 1
  316.      * instances happily if they are tagged as Type1 (!).
  317.      */
  318. #if 0
  319.         pputs(s, "<</Subtype/MMType1");
  320.         /****** NAME IS WRONG ******/
  321. #else
  322.         pputs(s, "<</Subtype/Type1");
  323. #endif
  324.     } else {
  325.         pputs(s, "<</Subtype/Type1");
  326.     }
  327.     }
  328.     bfname:
  329.     pputs(s, "/BaseFont");
  330.     pdf_put_name(pdev, pbfname->data, pbfname->size);
  331.     break;
  332.     case ft_CID_encrypted:
  333.     pputs(s, "<</Subtype/CIDFontType0");
  334.     /****** REQUIRES FONT TO EXIST ******/
  335.     pdf_write_CIDSystemInfo(pdev, &((const gs_font_cid0 *)pfd->base_font)->
  336.                 cidata.common.CIDSystemInfo);
  337.     goto bfname;
  338.     case ft_CID_TrueType:
  339.     pputs(s, "<</Subtype/CIDFontType2");
  340.     /****** REQUIRES FONT TO EXIST ******/
  341.     pdf_write_CIDSystemInfo(pdev, &((const gs_font_cid2 *)pfd->base_font)->
  342.                 cidata.common.CIDSystemInfo);
  343.     goto ttname;
  344.     case ft_TrueType:
  345.     pputs(s, "<</Subtype/TrueType");
  346.     ttname:
  347.     pputs(s, "/BaseFont");
  348.     /****** WHAT ABOUT STYLE INFO? ******/
  349.     pdf_put_name(pdev, pbfname->data, pbfname->size);
  350.     break;
  351.     default:
  352.     return_error(gs_error_rangecheck);
  353.     }
  354.     pprintld1(s, "/Type/Font/Name/R%ld", pdf_font_id(pef));
  355.     if (pef->index < 0 || pfd->base_font || pfd->FontFile_id)
  356.     pprintld1(s, "/FontDescriptor %ld 0 R", pdf_font_descriptor_id(pfd));
  357.     if (pef->write_Widths)
  358.     pdf_write_Widths(pdev, pef->FirstChar, pef->LastChar, pef->Widths);
  359.     /****** WRITE CIDFont [D]W[2] ******/
  360.     if (pef->Differences) {
  361.     long diff_id = pdf_obj_ref(pdev);
  362.     int prev = 256;
  363.     int i;
  364.  
  365.     pprintld1(s, "/Encoding %ld 0 R>>\n", diff_id);
  366.     pdf_end_separate(pdev);
  367.     pdf_open_separate(pdev, diff_id);
  368.     s = pdev->strm;
  369.     pputs(s, "<</Type/Encoding");
  370.     if (pef->BaseEncoding != ENCODING_INDEX_UNKNOWN)
  371.         pprints1(s, "/BaseEncoding/%s", encoding_names[pef->BaseEncoding]);
  372.     pputs(s, "/Differences[");
  373.     for (i = 0; i < 256; ++i)
  374.         if (pef->Differences[i].str.data != 0) {
  375.         if (i != prev + 1)
  376.             pprintd1(s, "\n%d", i);
  377.         pdf_put_name(pdev, pef->Differences[i].str.data,
  378.                  pef->Differences[i].str.size);
  379.         prev = i;
  380.         }
  381.     pputs(s, "]");
  382.     } else if (pef->BaseEncoding != ENCODING_INDEX_UNKNOWN) {
  383.     pprints1(s, "/Encoding/%s", encoding_names[pef->BaseEncoding]);
  384.     }
  385.     pputs(s, ">>\n");
  386.     return pdf_end_separate(pdev);
  387. }
  388.  
  389. /* Register a font for eventual writing (embedded or not). */
  390. private GS_NOTIFY_PROC(pdf_font_notify_proc);
  391. typedef struct pdf_font_notify_s {
  392.     gs_memory_t *memory;    /* used to allocate this object */
  393.     gx_device_pdf *pdev;
  394.     pdf_font_t *pdfont;        /* 0 if only for base_font */
  395.     pdf_font_descriptor_t *pfd;    /* 0 if not for base_font */
  396. } pdf_font_notify_t;
  397. gs_private_st_ptrs3(st_pdf_font_notify, pdf_font_notify_t, "pdf_font_notify_t",
  398.             pdf_font_notify_enum_ptrs, pdf_font_notify_reloc_ptrs,
  399.             pdev, pdfont, pfd);
  400. int
  401. pdf_register_font(gx_device_pdf *pdev, gs_font *font, pdf_font_t *ppf)
  402. {
  403.     /*
  404.      * Note that we do this allocation in stable font->memory, not
  405.      * pdev->pdf_memory.
  406.      */
  407.     pdf_font_descriptor_t *pfd = ppf->FontDescriptor;
  408.     gs_font *base_font = pfd->base_font;
  409.     gs_memory_t *fn_memory = gs_memory_stable(font->memory);
  410.     pdf_font_notify_t *pfn =
  411.     gs_alloc_struct(fn_memory, pdf_font_notify_t,
  412.             &st_pdf_font_notify, "pdf_register_font");
  413.     int code;
  414.  
  415.     if (pfn == 0)
  416.     return_error(gs_error_VMerror);
  417.     pfn->memory = fn_memory;
  418.     pfn->pdev = pdev;
  419.     pfn->pfd = pfd;
  420.     if (base_font == 0 || pfd->notified)
  421.     pfn->pfd = 0;
  422.     else if (base_font != font) {
  423.     /*
  424.      * We need two notifications: one for ppf->font, one for
  425.      * base_font.  Create the latter first.
  426.      */
  427.     pfn->pdfont = 0;
  428.     if_debug4('_', "[_]register 0x%lx: pdf_font_descriptor_t 0x%lx => 0x%lx, id %ld\n",
  429.           (ulong)pfn, (ulong)pfd, (ulong)base_font, base_font->id);
  430.     code = gs_font_notify_register(base_font, pdf_font_notify_proc, pfn);
  431.     if (code < 0)
  432.         return 0;
  433.     pfn = gs_alloc_struct(fn_memory, pdf_font_notify_t,
  434.                   &st_pdf_font_notify, "pdf_register_font");
  435.     if (pfn == 0)
  436.         return_error(gs_error_VMerror);
  437.     pfn->memory = fn_memory;
  438.     pfn->pdev = pdev;
  439.     pfn->pfd = 0;
  440.     }
  441.     pfd->notified = true;
  442.     pfn->pdfont = ppf;
  443. #ifdef DEBUG
  444.     if_debug4('_', "[_]register 0x%lx: pdf_font_t 0x%lx => 0x%lx, id %ld\n",
  445.           (ulong)pfn, (ulong)ppf, (ulong)font, font->id);
  446.     if (pfn->pfd)
  447.     if_debug3('_',
  448.           "                pdf_font_descriptor_t 0x%lx => 0x%lx, id %ld\n",
  449.           (ulong)pfd, (ulong)pfd->base_font, pfd->base_font->id);
  450. #endif
  451.     ppf->font = font;
  452.     return gs_font_notify_register(font, pdf_font_notify_proc, pfn);
  453. }
  454. private int
  455. pdf_finalize_font_descriptor(gx_device_pdf *pdev, pdf_font_descriptor_t *pfd)
  456. {
  457.     gs_font *font = pfd->base_font;
  458.     int code =
  459.     (font ? pdf_compute_font_descriptor(pdev, pfd, font, NULL) : 0);
  460.  
  461.     if (code >= 0) {
  462.     if (pfd->FontFile_id)
  463.         code = pdf_write_embedded_font(pdev, pfd);
  464.     else
  465.         code = pdf_write_FontDescriptor(pdev, pfd);
  466.     pfd->written = true;
  467.     }
  468.     pfd->base_font = 0;        /* clean up for GC */
  469.     return code;
  470. }
  471. private int
  472. pdf_font_notify_proc(void *vpfn /*proc_data*/, void *event_data)
  473. {
  474.     pdf_font_notify_t *const pfn = vpfn;
  475.     gx_device_pdf *const pdev = pfn->pdev;
  476.     pdf_font_t *const ppf = pfn->pdfont;    /* may be 0 */
  477.     pdf_font_descriptor_t *pfd = pfn->pfd;    /* may be 0 */
  478.     int code = 0;
  479.  
  480.     if (event_data)
  481.     return 0;        /* unknown event */
  482.  
  483.     if (ppf) {
  484.     /*
  485.      * The font of this pdf_font is about to be freed.  Just clear the
  486.      * pointer.
  487.      */
  488.     gs_font *const font = ppf->font;
  489.  
  490.     if_debug4('_',
  491.           "[_]  notify 0x%lx: pdf_font_t 0x%lx => 0x%lx, id %ld\n",
  492.           (ulong)pfn, (ulong)ppf, (ulong)font, font->id);
  493.     gs_font_notify_unregister(font, pdf_font_notify_proc, vpfn);
  494.     ppf->font = 0;
  495.     }
  496.  
  497.     if (pfd) {
  498.     /*
  499.      * The base_font of this FontDescriptor is about to be freed.
  500.      * Write the FontDescriptor and, if relevant, the FontFile.
  501.      */
  502.     gs_font *const font = pfd->base_font;
  503.     gs_memory_t *save_memory = font->memory;
  504.  
  505.     if_debug4('_',
  506.           "[_]  notify 0x%lx: pdf_font_descriptor_t 0x%lx => 0x%lx, id %ld\n",
  507.           (ulong)pfn, (ulong)pfd, (ulong)font, font->id);
  508.     gs_font_notify_unregister(font, pdf_font_notify_proc, vpfn);
  509.     /*
  510.      * HACK: temporarily patch the font's memory to one that we know is
  511.      * available even during GC or restore.  (Eventually we need to fix
  512.      * this by prohibiting implementations of font_info and glyph_info
  513.      * from doing any allocations.)
  514.      */
  515.     font->memory = &gs_memory_default;
  516.     code = pdf_finalize_font_descriptor(pdev, pfd);
  517.     font->memory = save_memory;
  518.     }
  519.     gs_free_object(pfn->memory, vpfn, "pdf_font_notify_proc");
  520.     return code;
  521. }
  522.  
  523. /* Write out the font resources when wrapping up the output. */
  524. private void
  525. pdf_font_unreg_proc(void *vpfn /*proc_data*/)
  526. {
  527.     pdf_font_notify_t *const pfn = vpfn;
  528.  
  529.     gs_free_object(pfn->memory, vpfn, "pdf_font_unreg_proc");
  530. }
  531. /* Write out the font resources when wrapping up the output. */
  532. int
  533. pdf_write_font_resources(gx_device_pdf *pdev)
  534. {
  535.     int j;
  536.  
  537.     for (j = 0; j < NUM_RESOURCE_CHAINS; ++j) {
  538.     pdf_font_t *ppf;
  539.     pdf_font_descriptor_t *pfd;
  540.  
  541.     for (ppf = (pdf_font_t *)pdev->resources[resourceFont].chains[j];
  542.          ppf != 0; ppf = ppf->next
  543.          ) {
  544.         if (PDF_FONT_IS_SYNTHESIZED(ppf))
  545.         pdf_write_synthesized_type3(pdev, ppf);
  546.         else if (!ppf->skip) {
  547.         gs_const_string font_name;
  548.  
  549.         pfd = ppf->FontDescriptor;
  550.         font_name.data = pfd->FontName.chars;
  551.         font_name.size = pfd->FontName.size;
  552.         /*
  553.          * If the font is based on one of the built-in fonts,
  554.          * we already ensured it uses the built-in name.
  555.          * If it is a subset, we must write the Widths even if
  556.          * it is a built-in font.
  557.          */
  558.         if (pdf_has_subset_prefix(font_name.data, font_name.size))
  559.             ppf->write_Widths = true;
  560.         pdf_write_font_resource(pdev, ppf, &font_name, &font_name);
  561.         if (ppf->font)
  562.             gs_notify_unregister_calling(&ppf->font->notify_list,
  563.                          pdf_font_notify_proc, NULL,
  564.                          pdf_font_unreg_proc);
  565.         }
  566.     }
  567.     for (pfd = (pdf_font_descriptor_t *)pdev->resources[resourceFontDescriptor].chains[j];
  568.          pfd != 0; pfd = pfd->next
  569.          ) {
  570.         if (!pfd->written) {
  571.         pdf_finalize_font_descriptor(pdev, pfd);
  572.         if (pfd->base_font)
  573.             gs_notify_unregister_calling(&pfd->base_font->notify_list,
  574.                          pdf_font_notify_proc, NULL,
  575.                          pdf_font_unreg_proc);
  576.         }
  577.     }
  578.     }
  579.     return 0;
  580. }
  581.